/*
 * @Author: fangquan
 * @Date: 2020-06-10 13:38:32
 * @Last Modified by: fangquan
 * @Last Modified time: 2020-06-10 17:47:58
 * @Usage 公共接口集合
 */

import request from "@/utils/request";
import config from "@/config";

import { formatParams } from "@/utils/common";

let domain = process.env.VUE_APP_TYPE == "online" ? "http://xuehuli.com" : "http://dev.yatiku.com";

const EXTRA = {
  showLoading: false
}

/**
 * 获取access_token
 */
export let getAccessToken = (params) => request.post(
  `${domain}/app/v1/getAccessToken`,
  {
    brandType: config.brandType,
    clientType: config.clientType,
    clientVersion: config.clientVersion,
    ...params
  },EXTRA);

/**
 * 获取AppId
 */
export let getAppId = (params) => request.post(`${domain}/activity/getApAc`, params, EXTRA);

/**
 * 获取用户信息
 */
export let getUserInfo = (params) => request.post(`${domain}/activity/getUserInfo`, params, EXTRA);

/**
 * 获取所有用户信息
 */
export let getUserAllInfo = (params) => request.post(`${domain}/activity/getUserAllInfo`, params, EXTRA);

/**
 * 写公共参数cookie
 */
export let writeCookie = (params) => request.post(`${domain}/app/v1/tool/writeCookie`, params);

/**
 * 微信JS-SDF验证
 */
export let checkWechatSDK = (params) => request.post(`${domain}/activity/jsapiTicket?urltimer=${new Date().getTime()}`,{
  url: location.href,
  accid: formatParams().accId || 1,
  access_token: localStorage.getItem("access_token") || "",
  ...params
}, EXTRA);

/**
 * 手机登录
 */
export let loginByTel = (params) => request.post(`${domain}/activity/loginByTel`, params);

/**
 * 获取省市区信息
 */
export let listAddress = (params) => request.get(`${domain}/tool/address/all`, params);

/**
 * 上传文件到oss
 */
export let uploadFile = (params) => request.post("http://app.yatiku.com/tool/uploadFileOss", params, {
  headers: {
    "Content-Type": "multipart/form-data"
  }
});

/**
 * 上传base64图片
 */
export let uploadBase64Img = (params) => request.post(`${domain}/tool/uploadBase64Img`, params);

/**
 * 清除cookie
 */
export let cleanCookie = (params) => request.get(`${domain}/activity/cleanCookie`, params);